﻿using BaseClass;
using Microsoft.AspNetCore.Mvc;
using System;
using NodeDTO = KG.SystemService.NodeDTO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KG.ServiceLogic.Logic;

namespace KG.API.Controllers
{
    /// <summary>
    /// 节点管理
    /// </summary>
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    public class nodeController : Controller
    {
        private NodeLogic _nodeLogic;
        public nodeController(NodeLogic nodeLogic)
        {
            _nodeLogic = nodeLogic;
        }
        /// <summary>
        /// 添加节点接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<NodeDTO.OutputId> add(NodeDTO.InputAdd req)
        {
            var result = new Response<NodeDTO.OutputId>();
            try
            {
                result.Result = _nodeLogic.AddNode(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 删除节点接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<NodeDTO.OutputId> delete(NodeDTO.InputDelete req)
        {
            var result = new Response<NodeDTO.OutputId>();
            try
            {
                result.Result = _nodeLogic.DeleteNode(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 更新节点接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<NodeDTO.OutputId> update(NodeDTO.InputUpdate req)
        {
            var result = new Response<NodeDTO.OutputId>();
            try
            {
                result.Result = _nodeLogic.UpdateNode(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 加载节点
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<NodeDTO.OutputLoad> load([FromQuery] NodeDTO.InputLoad req)
        {
            var result = new Response<NodeDTO.OutputLoad>();
            try
            {
                result.Result = _nodeLogic.LoadNode(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 查看单个节点信息
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<NodeDTO.OutputGet> get([FromQuery] NodeDTO.InputGet req)
        {
            var result = new Response<NodeDTO.OutputGet>();
            try
            {
                result.Result = _nodeLogic.GetNode(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<NodeDTO.OutputLoad> complexLoad(NodeDTO.InputComplexLoad req)
        {
            var result = new Response<NodeDTO.OutputLoad>();
            try
            {
                result.Result = _nodeLogic.ComplexLoad(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 加载节点标签
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<NodeDTO.OutputLabelLoad> labelLoad()
        {
            var result = new Response<NodeDTO.OutputLabelLoad>();
            try
            {
                result.Result = _nodeLogic.LabelLoad();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }

        [HttpPost]
        public Response<string> deleteAll()
        {
            var result = new Response<string>();
            try
            {
                result.Result = _nodeLogic.DeleteAllNode();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
